﻿@using LanDBom.Resources
@{
    ViewBag.Title = "Valuation_statement";
}

<h2>申请单总览</h2>

@section styles{
    <style>
        input {
            width: 100%;
        }

        fieldset {
        }

            fieldset div {
                margin-bottom: 5px
            }

        #finddiv1 {
            width: 100%;
        }

        select {
            width: 100%;
        }

        #viewdiv {
            width: 100%;
            overflow-x: scroll;
            overflow-y: hidden;
            height: 70vh;
        }

        #btable {
            width: 240%;
        }

        .rz {
            width: 300px;
        }
        .scrollTbody {
            overflow: auto;
            width: 100%;
        }

        .table td, .table th {
            word-break: keep-all;
            white-space: nowrap;
        }
            .table td:nth-child(2), .table th:nth-child(2) {
                width: 40px;
            }
    </style>
}

<from>
    <div id="WT_dh_mb2" style="display: none; position: absolute; border: 1px black solid; left: 25%; top: 33%; background-color: white; background-color: #f1f1f1;height:200px;width:300px">
        <div style="text-align: right; background-color: #84acde;"><span class="WT_qxbh2" style=" margin: 20px;"><i class="bi bi-x-square"></i></span></div>
        <div style="margin: 20px 10px; padding: 10px; background-color: #fff;">
            <div id="WJ_XZLJ"></div>
        </div>
        <div style="text-align:center"><button class="WT_qxbh2">@Resource.String126</button></div>
    </div>
    <div id="finddiv1">
        <fieldset class="boun">
            <legend class="len">@Resource.String374</legend>
            <div class="row">
                <div class="col-2">创建日期从：</div>
                <div class="col-2"><input  type="date" id="qssj"/></div>
                <div class="col-2">到:</div>
                <div class="col-2"><input type="date" id="jssj" /></div>
                <div class="col-4"></div>
                <div class="col-2">申请单号</div>
                <div class="col-2"><input type="text" id="bian"/></div>
                <div class="col-2">@Resource.String375</div>
                <div class="col-2"><input type="text" id="BB_SQ_xmmc" /></div>
                <div class="col-2">@Resource.String376</div>
                <div class="col-2"><input type="text" id="BB_SQ_khmc" /></div>
                <div class="col-2">@Resource.String377</div>
                <div class="col-2"><input type="text" id="BB_SQ_gjz" /></div>
                <div class="col-2">项目状态</div>
                <div class="col-2">
                    <select id="xmlx">
                        <option value="0">请选择</option>
                        <option value="1">项目完成</option>
                        <option value="2">项目执行中</option>
                        <option value="3">项目结束</option>
                     </select>
                </div>
                <div class="col-4"></div>
                <div class="col-2 btn-sm  btn-warning" id="BB_WT_cx" style="text-align:center">@Resource.String374</div>&nbsp;
                <div class="col-2  btn-sm  btn-warning" id="BB_WT_scbb" style="text-align:center">@Resource.String380</div>
            </div>
        </fieldset>
    </div>
    <div id="viewdiv">
        <table class="tab table" id="btable" style="table-layout:fixed;">
            <thead class="thead-light">
                <tr style="text-align:center;">
                    <th scope="col" style="width:30px;"><input type="checkbox" style="width:20px" id="dkek"/></th>
                    <th></th>
                    <th scope="col">申请单号</th>
                    <th scope="col">业务员</th>
                    <th scope="col">客户名称</th>
                    <th scope="col">品名</th>
                    <th scope="col">采购负责人</th>
                    <th scope="col">客户要求阶梯价</th>
                    <th scope="col">材质</th>
                    <th scope="col">报价要求</th>
                    <th scope="col">发起日期</th>
                    <th scope="col">要求完成</th>
                    <th scope="col">GSO提交日期</th>
                    <th scope="col">报价日期</th>
                    <th scope="col">供应商</th>
                    <th scope="col">采购备注</th>
                    <th scope="col">MOQ</th>
                    <th scope="col">理论价格</th>
                    <th scope="col">单价</th>
                    <th scope="col">生产周期</th>
                    <th scope="col">模具印版</th>
                    <th scope="col">项目状态</th>
                </tr>
            </thead>
            <tbody data-spy="scroll" id="BB_WT_tb" style="height:590px">
            </tbody>
        </table>
    </div>
    <div style="display:none" id="dvasf"></div>
    <div style="display:none" id="dadsff"></div>
    @Html.ActionLink(Resource.String394, "Inspect_Contracts", new { Controller = "Contracts", Action = "Inspect_Contracts" }, new { @class = "btn" })
</from>

@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            $("#li24").css({ "color": "black", "background-color": "white" })
            get_contracts()
            Generate_report()

            $(document).on("click", "#dkek", function (e) {
                if ($("#dkek").prop("checked") == true) {
                    console.log(1)
                    $(".enidh").prop("checked", true)
                }
                else {
                    $(".enidh").prop("checked", false)
                }
            })

            $(document).on("click", "#BB_WT_cx", function () {
                get_contracts()
            })
            //搜索申请单信息
            function get_contracts() {
                var BB_SQ_xmmc = $("#BB_SQ_xmmc").val()
                var BB_SQ_khmc = $("#BB_SQ_khmc").val()
                var BB_SQ_sqrq = $("#BB_SQ_sqrq").val()
                var BB_SQ_gjz = $("#BB_SQ_gjz").val()
                var qssj = $("#qssj").val()
                var jssj = $("#jssj").val()
                var bian = $("#bian").val()
                var xmlx = $("#xmlx").val()
                console.log("BB_SQ_xmmc", BB_SQ_xmmc, "BB_SQ_khmc", BB_SQ_khmc, "BB_SQ_gjz", BB_SQ_gjz, "state", 1, "qssj",qssj, "jssj",jssj, "danhao",bian, "xmlx", xmlx)
                $.ajax({
                    url: '/Procure/Valuation_statement',
                    type: 'GET',
                    data: { "BB_SQ_xmmc": BB_SQ_xmmc, "BB_SQ_khmc": BB_SQ_khmc, "BB_SQ_gjz": BB_SQ_gjz, "state": 1, "qssj": qssj, "jssj": jssj, "danhao": bian, "xmlx": xmlx },
                    success: function (wt) {
                        console.log(wt)
                        newWT(wt)
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }
            function newWT(wt) {
                console.log(wt)
                $('#BB_WT_tb tr').remove();
                $.each(wt, function (i, item) {
                    /*$.ajax({
                        url: "/Procure/Valuation_statement",
                        type: 'POST',
                        data: { "state": 2, "id": item.BOM2_id },
                        success: function (text) {
                            $("#dvasf").text(text)
                        },
                        error: function (text) {
                        }
                    })
                    $.ajax({
                        url: "/Procure/Valuation_statement",
                        type: 'POST',
                        data: { "state": 3, "id": item.BOM2_id },
                        success: function (text) {
                            $("#dadsff").text(text)
                        },
                        error: function (text) {
                        }
                    })*/
                    //---
                    var zhuangt = ""
                    if (item.App_bu == "-99") {
                        zhuangt = "项目结束"
                    }
                    else {
                        zhuangt="项目执行中"
                    }
/*
                    var dvasf = $("#dvasf").text()
                    var dadsff = $("#dadsff").text()
                    */
                    var $zc = $(`
                        <tr>
                            <td  style="width:30px;"><input type="checkbox" style="width:20px;" class="enidh"/></td>
                            <td  id="WT_SJ_S-1">${item.Inf_id}</td>
                            <td  id="WT_SJ_S0">${item.AP_bian}</td>
                            <td  id="WT_SJ_S1">${item.App_fzr}</td>
                            <td  id="WT_SJ_S2">${item.App_Kehu}</td>
                            <td  id="WT_SJ_S3"></td>
                            <td  id="WT_SJ_S3">${item.DE_nae}</td>
                            <td  id="WT_SJ_S4">${item.Inf_JT}</td>
                            <td  id="WT_SJ_S5">${item.FM_ms}</td>
                            <td  id="WT_SJ_S6"></td>
                            <td  id="WT_SJ_S7">${item.App_qishi}</td>
                            <td  id="WT_SJ_S8">${item.App_JTime}</td>
                            <td  id="WT_SJ_S9">${item.Inf_ftime}</td>
                            <td  id="WT_SJ_S10">${item.Inf_htime}</td>
                            <td  id="WT_SJ_S11">${item.Inf_gong}</td>
                            <td  id="WT_SJ_S12">${item.Inf_bei}</td>
                            <td  id="WT_SJ_S13">${item.Inf_JT}</td>
                            <td  id="WT_SJ_S14"><textarea>${item.BOM2_mioa}</textarea ></td>
                            <td  id="WT_SJ_S15">${item.Inf_huiP}</td>
                            <td  id="WT_SJ_S16">${item.Inf_sczq}</td>
                            <td  id="WT_SJ_S17">${item.Inf_ybfy}</td>
                            <td  id="WT_SJ_S18">${zhuangt}</td>
                        </tr>
                    `);
                    $('#BB_WT_tb').append($zc);
                })
            }
            //下载excel
            function Generate_report() {
                $(document).on("click", "#BB_WT_scbb", function () {
                    var CG_XX = [];
                    var WT_RZ = [];
                    var check = $("input[class=enidh]:checked").parent().parent().length;
                    if (check <= 0) {
                        alert("至少选中一行！");
                    }
                    else {
                        $("input[class=enidh]:checked").parent().parent().each(function (index, obj) {
                            CG_XX.push({
                                AP_bian: $("td[id='WT_SJ_S-1']",obj).text()
                            })
                            console.log("共" + CG_XX.length + "数据");
                            console.log(CG_XX);
                        })
                        var Employee_path = $("#Login_path").text()
                        console.log(Employee_path)

                        var userInput = prompt("请输入文件名：", "");

                        if (userInput != null) {
                            $.ajax({
                                url: "/Procure/DownloadExcel2",
                                type: 'POST',
                                data: { "Designdraws": CG_XX, "WT_CD": CG_XX.length, "state": 1, "excelName": userInput, "Employee_path": Employee_path },
                                success: function (text) {
                                    $("#WT_dh_mb2").css({ "display": "block" })
                                    $("#WJ_XZLJ").append($(`<a href="/Contracts/Download_file?path=${text}" id="log_SZ" class="WT_qxbh2">下载</a>`))
                                },
                                error: function (text) {
                                    alert("系统错误");
                                }
                            })
                        }
                    }
                })
            }
            $(document).on("click", ".WT_qxbh2", function () {
                $("#WT_dh_mb2").css({ "display": "none" })
                $("#WJ_XZLJ a").remove()
            })
        })
    </script>
}